<%= javascript_include_tag "prototype" %>
<%= javascript_include_tag "util" %>
<%= javascript_include_tag "calendar" %>
<script type="text/javascript">
 
        function checkNum(flag, msg_id, obj_name, msg_text){
                if (flag) {
                        if ($(obj_name).value != "" && ! digCheck($(obj_name).value))
                        {
                                $(msg_id).innerText = msg_text;
                                $(msg_id).style.display = "block";
                                return false;
                        }
                        else return true;
                }
                else {
                        $(msg_id).style.display = "none";
                }
        }

        function checkDate()
        {
                if ( checkNum(true,'id_serial','id_paper_serial','条形码编号输入错误') )
                        frmSalePaper.submit();
        }

        function showAgentWindow(id)
        {
                window.open("/other_org/agent_info/"+id,"_blank","height=450,width=550,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
        }

        function showPaperWindow(id)
        {
                window.open("/sale/show_print_sale_paper/"+id,"_blank","height=450,width=750,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
        }

</script>
<h1>订单管理 - <span id="secondHeading"><%='审批订单' if @pageType.eql? 'AD'%><%='填写条形码' if @pageType.eql? 'NU'%><%='补齐订单' if @pageType.eql? 'GO'%></span></h1>
<%if @pageType.eql? 'NU'%>
<form id="input-form" name="frmSalePaper" action="/sale/address_sale_paper" method="post">
<table id="INPUT_TABLE" style="margin-left:30px;">
	<tr>
                <td width="15%">
    <input type="hidden" name="pageType" value="<%=@pageType%>"/>
    条形码编号：
                    </td>
                <td>
    <input id="id_paper_serial" type="text" name="paper_serial" size="20" maxlength="20" onfocus="checkNum(false,'id_serial')" onblur="checkNum(true,'id_serial','id_paper_serial','条形码编号输入错误')">&nbsp;<br/><div class="redNsg" id="id_serial" style="display:none;"></div>
                </td>
	</tr>
	<tr>
        <td>        
        起始时间：
</td>
          <td>
        <!-- <input id="beginDate" type="text" name="from"> -->
        <script language=javascript>
        var beignDate=new dateSelector();
        beignDate.inputID='beginDate';
        beignDate.inputName='from';
        beignDate.display();
        </script>
                </td>
	</tr>
        <tr>
<td>
结束时间：
</td>
<td>
        <!-- <input id="endDate" type="text" name="to"> -->
        <script language=javascript>
        var endDate=new dateSelector();
        endDate.inputID='endDate';
        endDate.inputName='to';
        endDate.display();
</script>
</td>
	</tr>
	<tr>
        <td colspan="2" align="right">　　　　　
        <input  type="button" value="查询" class="sub" onclick="checkDate()">
 </td>
	</tr>
</table>
</form>
<%end%>
<% if @flash[:notice] -%>
<div id="notice"><%= @flash[:notice] %></div>
<% end -%>
<TABLE border="0" id="LIST_TB">
	<TR id="LIST_TB_TITLE">
      <td nowrap>编号</td>
      <td nowrap>销售</td>
      <td nowrap>购买方</td>
      <td>销售日期</td>
      <td>支付</td>
      <td<%if @pageType.eql? 'AD'%> colspan="2"<%end%>>相关操作</td>
    </tr>
    <%@sale_papers.each do |paper|%>
    <TR id="LIST_TB_CONTENT1">
            <td><a href="javascript:showPaperWindow(<%=paper.id%>)"><%=paper.id%></a></td>
      <td><%=paper.employee.name%></td>
      <td><a href="javascript:showAgentWindow(<%=paper.agent.id%>)"><%=paper.agent.name%></a></td>
      <td><%=paper.sale_date_at%></td>
      <td><%='<font color="red">未支付</font>' if paper.charge.eql? 'no'%><%='<font color="green">已支付</font>' if paper.charge.eql? 'yes'%></td>
      <%if @pageType.eql? 'AD'%>
      <td><a href="/sale/address_sale_paper?id=<%=paper.id%>&state=OK"><img src="/images/yes.gif" alt="批准"></a></td>
      <td><a href="/sale/address_sale_paper?id=<%=paper.id%>&state=NO"><img src="/images/no.gif" alt="不批准"></a></td>
      <%elsif @pageType.eql? 'NU'%>
      <td><a href="/sale/list_sale_paper_item?salePaperId=<%=paper.id%>&agentId=<%=paper.agent.id%>&type=NU"><img src="/images/edit.gif" alt="回填条形码"></a></td>
      <%elsif @pageType.eql? 'GO'%>
      <td><a href="/sale/list_sale_paper_item?salePaperId=<%=paper.id%>&type=GO"><img src="/images/edit.gif" alt="补齐订单"></a></td>
      <%end%>
   </tr>
    <%end%>
</table>
<table>
        <tr>
                <td>
                        <input type="button" value="打印当前页" class="sub" onclick="openPrintWindow('LIST_TB')"/>
                        <input type="button" value="导出当前数据" class="sub" onclick="CellAreaExcel('LIST_TB')"/>
                </td>
        </tr>
</table>
